
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for confirmation_cancel_account.
	''' </summary>
	Public Partial Class confirmation_cancel_account
		Inherits BaseWebPage
		Protected hlKeepGroupAccount As System.Web.UI.WebControls.HyperLink
		Protected lbCancelGroupAccount As System.Web.UI.WebControls.LinkButton
		Protected isGroupMode As Boolean = False
		Private grpID As Integer = -1
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.CONFIRMATION_CANCEL_ACCOUNT_PAGE;
			Dim grp As Group = Nothing
			Dim usr As User = Me.LoggedUser

			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			' init page from XML
			Me.initPageTitles(Constants.CONFIRMATION_CANCEL_ACCOUNT, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			If Request.Params(Constants.GROUP_PARAM) <> Nothing AndAlso Request.Params(Constants.GROUP_PARAM) <> "" Then
				grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
				isGroupMode = True
				Try
					grp = Groups.GetGroupByID(grpID)
				Catch
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End Try

				If grp = Nothing Then
					Throw New Exception(Constants.ERROR_MESSAGE_GROUP_DOESNT_EXIST_ERROR)
				End If

				If grp.Uid <> usr.ID Then
					Throw New Exception(Constants.ERROR_MESSAGE_ONLY_MODERATOR_ACCESS)
				End If
			End If

			If isGroupMode Then
				Dim pageFrom As String = ""
				If Request.Params(Constants.PAGE_FROM) <> Nothing AndAlso Request.Params(Constants.PAGE_FROM) <> "" Then
					pageFrom = Request.Params(Constants.PAGE_FROM)
				End If
				lblPageTitle.Text = Me.GetPageConstText(htPageConstants, "CONST_GroupPageTitle_TEXT")
				trUserAccountInfo.Visible = False
				trGroupAccountInfo.Visible = True
				If pageFrom = Constants.MY_GROUPS Then
					hlKeepAccount.NavigateUrl = "../" + Constants.MY_GROUPS
				Else
					hlKeepAccount.NavigateUrl = "../" + Constants.EDIT_GROUP_BASIC + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				End If
				hlKeepAccount.Text = Me.GetPageConstText(htPageConstants, "CONST_KeepGroup_TEXT")
				lbCancelAccount.Text = Me.GetPageConstText(htPageConstants, "CONST_CancelAccount_TEXT")
				hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + grpID
				hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)
			Else
				trUserAccountInfo.Visible = True
				trGroupAccountInfo.Visible = False
			End If
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub lbCancelAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If isGroupMode Then
				Dim grp As Group = Groups.GetGroupByID(grpID)
				grp.DoDelete()
				Response.Redirect(Constants.DELETE_ACCOUNT + "?" + Constants.GROUP_PARAM + "=" + grpID)
			Else
				Dim usr As User = Me.LoggedUser
				usr.UnRegister(txtFeedbackText.Text)
				Response.Cookies(Constants.cookieEmail).Expires = DateTime.MinValue
				Response.Cookies(Constants.cookiePassword).Expires = DateTime.MinValue
				Response.Redirect(Constants.DELETE_ACCOUNT + "?logout=1")
			End If
		End Sub

		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






